$j(document).ready(function() {
   switchQueryOnload();
});
function check_all(form_object, val) {
	for (var i=0;i<form_object.elements.length;i++) {
		var e = form_object.elements[i];
		if ((e.name != 'check_all_box') && (e.type=='checkbox') && (!e.disabled)) {
			e.checked = val;
		}
	}
}

function getCheckboxSize(obj) {
	var size = 0;
	if ( !obj ) {
		return size;
	} 
	for ( var i = 0; i < obj.length; i++ ) {
		var e = obj[i];
		if ( e.checked ) {
			size++;
		}
	}
	return size;
}

function check() { 
    var fieldBox = document.getElementsByName('selectAll'); 
    var field = document.getElementsByName('checkboxList');
    if (fieldBox[0].checked == true) { 
        for (i = 0; i < field.length; i++) { 
            field[i].checked = true;
        }  
    } else { 
        for (i = 0; i < field.length; i++) { 
            field[i].checked = false; 
        }
    } 
}

function confirmOp() {
    var checked = false;
    var field = document.getElementsByName('checkboxList');
    for (var i = 0; i < field.length; i++) { 
        if (field[i].checked) {
            checked = true;
            break;
        }
    }
    if (checked) {
        return confirm("Do you really want to delete these records?");
    } else {
        alert("Pls select the records that you want to delete!");
        return false;
    }
}

function prompConfirm(url, message) {
  /**
  if (confirm(message)) {
    $j.post(url ,
      function() {
        window.location.reload();
      }
    );
  }
  */
  if (window.confirm(message)) {
    window.location = url;
  }
}    

/**
	get current row of table from event form
*/
getMyRowIndex = function(event) {
  var obj = (event.target)?event.target:window.event.srcElement;
  while(true) {
    if ( obj.tagName == "TR" ) {
      return obj.rowIndex;
    }
    if ( obj.parentNode ) {
      obj = obj.parentNode;
    }
    else {
      obj = obj.parentElement;
    }
  }
  return -1;
};

function commonClearQuery() {
  $j('#queryForm input[type!="submit"]').val('');
  $j('#queryForm select').val('');
  // $j('#queryForm').submit();
}

function commonHideQuery(){
	if($('queryArea').style.display=='none'){
	 $('queryArea').style.display='';
	}else{
	 $('queryArea').style.display='none';
	} 
}

function commonHideMenu(){
	if($('tile-menu').style.display=='none'){
	 $('tile-menu').style.display='inline';
	 $('tile-content').style.marginLeft='120px';
	}else{
	 $('tile-menu').style.display='none';
	 $('tile-content').style.marginLeft='0px'; 
    }
}

function switchQuery(){  
 if($j('#advance_search').attr("class")=='wwFormTableHide'){
 	 $('advance_search').className="wwFormTable";	 
 	 document.cookie="adsearch=1";
 	 $j('#statusbar a:last').html("普通搜索");
	 
	}else{
	 $('advance_search').className="wwFormTableHide";
	 document.cookie="adsearch=0";
	 clearAdSearch();
	 $j('#statusbar a:last').html("高级搜索");
	} 
}

function clearAdSearch(){
	$j('#advance_search input').val('');
    $j('#advance_search select').val('');
}



function switchQueryOnload(){
	if($('advance_search')==null){
		return;
	}
	var strCookie=document.cookie;  
	var arrCookie=strCookie.split("; "); 
	var adsearch; 
	for(var i=0;i<arrCookie.length;i++){ 
	   var arr=arrCookie[i].split("="); 
	   if("adsearch"==arr[0]){ 
	      adsearch=arr[1]; 
	      break; 
	   } 
	}
	//alert(adsearch);
	if(adsearch==1){
	  $('advance_search').className="wwFormTable";
	}else{
	  $('advance_search').className="wwFormTableHide";
	}
 
}
